<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>售后管理 - 电动车销售系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/salesadmin/aftersaleslist.css">
</head>
<body>
<header class="dashboard-header">
    <div class="container">
        <div class="d-flex justify-content-between align-items-center">
            <div>
                <h1 class="h3 mb-0"><i class="bi bi-bicycle"></i> 电动车销售管理系统</h1>
                <p class="mb-0 opacity-75">售后管理 - 售后订单列表</p>
            </div>
            <div class="d-flex align-items-center">
                <div class="me-3">
                    <span class="d-none d-md-inline">${currentUser.name}</span>
                    <div class="badge bg-light text-dark">
                        <i class="bi bi-person-circle me-1"></i> 售后管理员
                    </div>
                </div>
                <div class="dropdown">
                    <button class="btn btn-light rounded-circle p-1" type="button" data-bs-toggle="dropdown">
                        <i class="bi bi-gear fs-5"></i>
                    </button>
                    <ul class="dropdown-menu dropdown-menu-end">
                        <li><a class="dropdown-item" href="${pageContext.request.contextPath}/change_password.jsp"><i class="bi bi-lock me-2"></i> 修改密码</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item text-danger" href="${pageContext.request.contextPath}/LogoutServlet"><i class="bi bi-box-arrow-right me-2"></i> 退出登录</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</header>

<div class="container mb-5">
    <div class="search-bar fade-in">
        <form action="afterSalesAdmin" method="get" class="d-flex align-items-center w-100">
            <input type="hidden" name="action" value="list">
            <i class="bi bi-search me-2"></i>
            <input type="text" id="id" name="id" value="${param['id']}"
                   class="form-control border-0 shadow-none"
                   placeholder="请输入订单ID">
            <button type="submit" class="btn btn-primary ms-2">
                <i class="bi bi-search me-1"></i> 查询
            </button>
        </form>
    </div>

    <div class="dashboard-card shadow fade-in">
        <div class="card-header d-flex justify-content-between align-items-center">
            <div>
                <h5 class="card-title"><i class="bi bi-tools me-2 text-primary"></i>售后订单列表</h5>
                <p class="card-subtitle">所有售后订单信息</p>
            </div>
            <a href="afterSalesAdmin?action=addForm" class="btn-add">
                <i class="bi bi-plus-circle me-1"></i> 添加新售后订单
            </a>
        </div>

        <div class="card-body p-0">
            <div class="table-container">
                <table class="table">
                    <thead>
                    <tr>
                        <th>售后ID</th>
                        <th>关联销售订单ID</th>
                        <th>处理用户ID</th>
                        <th>问题描述</th>
                        <th>状态</th>
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:choose>
                        <c:when test="${not empty afterSalesList}">
                            <c:forEach items="${afterSalesList}" var="afterSale">
                                <tr class="order-item">
                                    <td>${afterSale.id}</td>
                                    <td>${afterSale.saleOrderId}</td>
                                    <td>${afterSale.userId}</td>
                                    <td>${afterSale.problem}</td>
                                    <td>
                                            <span class="status-badge status-${afterSale.status == 0 ? 'pending' : afterSale.status == 1 ? 'processing' : 'resolved'}">
                                                <c:choose>
                                                    <c:when test="${afterSale.status == 0}">未处理</c:when>
                                                    <c:when test="${afterSale.status == 1}">处理中</c:when>
                                                    <c:when test="${afterSale.status == 2}">已解决</c:when>
                                                    <c:otherwise>未知状态</c:otherwise>
                                                </c:choose>
                                            </span>
                                    </td>
                                    <td>${afterSale.createTime}</td>
                                    <td>
                                        <div class="action-buttons">
                                            <a href="afterSalesAdmin?action=editForm&id=${afterSale.id}"
                                               class="btn btn-edit"
                                               title="编辑订单">
                                                <i class="bi bi-pencil me-1"></i> 编辑
                                            </a>
                                            <a href="afterSalesAdmin?action=delete&id=${afterSale.id}"
                                               class="btn btn-delete"
                                               title="删除订单"
                                               onclick="return confirm('确认删除售后订单 ${afterSale.id} 吗？')">
                                                <i class="bi bi-trash me-1"></i> 删除
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                            </c:forEach>
                        </c:when>
                        <c:otherwise>
                            <tr>
                                <td colspan="7">
                                    <div class="empty-state py-5">
                                        <i class="bi bi-inboxes"></i>
                                        <h5 class="mt-3">暂无售后订单数据</h5>
                                        <p class="text-muted">没有找到匹配的售后订单记录</p>
                                    </div>
                                </td>
                            </tr>
                        </c:otherwise>
                    </c:choose>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
    // 自动关闭消息提示（如果有）
    document.querySelectorAll('.alert .btn-close').forEach(button => {
        button.addEventListener('click', function() {
            this.closest('.alert').style.display = 'none';
        });
    });

    // 5秒后自动关闭消息提示
    setTimeout(() => {
        document.querySelectorAll('.alert').forEach(alert => {
            alert.style.display = 'none';
        });
    }, 5000);

    // 表单提交确认
    document.querySelectorAll('.btn-delete').forEach(button => {
        button.addEventListener('click', function(e) {
            if (!confirm('确认删除该售后订单吗？')) {
                e.preventDefault();
            }
        });
    });
</script>
</body>
</html>